
package com.market.dao;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.market.bean.Subknowledge;
import com.market.dao.hibernate.GenericDaoHibernate;

/**
 * Data access object (DAO) for domain model class Subknowledge.
 * 
 * @see com.market.bean.Subknowledge
 * @author MyEclipse - Hibernate Tools
 */
public class SubknowledgeDAO extends GenericDaoHibernate<Subknowledge, Long>
{

    public SubknowledgeDAO(Class<Subknowledge> persistentClass)
    {
        super(persistentClass);
        // TODO Auto-generated constructor stub
    }

    public SubknowledgeDAO()
    {
        super();
    }
    
    private static final Logger log = LoggerFactory.getLogger(SubknowledgeDAO.class);

    // property constants

    protected void initDao()
    {
        // do nothing
    }

    public Subknowledge save(Subknowledge transientInstance)
    {
        log.debug("saving Subknowledge instance");
        try
        {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        }
        catch (RuntimeException re)
        {
            log.error("save failed", re);
            throw re;
        }
        return transientInstance;
    }

    public void delete(Subknowledge persistentInstance)
    {
        log.debug("deleting Subknowledge instance");
        try
        {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        }
        catch (RuntimeException re)
        {
            log.error("delete failed", re);
            throw re;
        }
    }

    public Subknowledge findById(java.lang.Long id)
    {
        log.debug("getting Subknowledge instance with id: " + id);
        try
        {
            Subknowledge instance = (Subknowledge)getHibernateTemplate().get("com.market.bean.Subknowledge", id);
            return instance;
        }
        catch (RuntimeException re)
        {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(Subknowledge instance)
    {
        log.debug("finding Subknowledge instance by example");
        try
        {
            List results = getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        }
        catch (RuntimeException re)
        {
            log.error("find by example failed", re);
            throw re;
        }
    }

    public List findByProperty(String propertyName, Object value)
    {
        log.debug("finding Subknowledge instance with property: " + propertyName + ", value: " + value);
        try
        {
            String queryString = "from Subknowledge as model where model." + propertyName + "= ?";
            return getHibernateTemplate().find(queryString, value);
        }
        catch (RuntimeException re)
        {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    public Subknowledge merge(Subknowledge detachedInstance)
    {
        log.debug("merging Subknowledge instance");
        try
        {
            Subknowledge result = (Subknowledge)getHibernateTemplate().merge(detachedInstance);
            log.debug("merge successful");
            return result;
        }
        catch (RuntimeException re)
        {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Subknowledge instance)
    {
        log.debug("attaching dirty Subknowledge instance");
        try
        {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        }
        catch (RuntimeException re)
        {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(Subknowledge instance)
    {
        log.debug("attaching clean Subknowledge instance");
        try
        {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        }
        catch (RuntimeException re)
        {
            log.error("attach failed", re);
            throw re;
        }
    }

    public static SubknowledgeDAO getFromApplicationContext(ApplicationContext ctx)
    {
        return (SubknowledgeDAO)ctx.getBean("SubknowledgeDAO");
    }
}
